package cn.rokhdelar.ams.management.service.impl;

import cn.rokhdelar.ams.common.domain.vo.PageVO;
import cn.rokhdelar.ams.management.domain.po.SysOperationLog;
import cn.rokhdelar.ams.management.domain.query.OperationLogQuery;
import cn.rokhdelar.ams.management.domain.vo.OperationLogVO;
import cn.rokhdelar.ams.management.mapper.SysOperationLogMapper;
import cn.rokhdelar.ams.management.service.SysOperationLogService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @author Rokhdelar
 * @since 2025/3/24 -- 16:16
 **/
@Service
public class SysOperationLogServiceImpl extends ServiceImpl<SysOperationLogMapper, SysOperationLog> implements SysOperationLogService {
    /**
     * 获取操作日志列表
     * @param query 查询对象
     * @return 操作日志列表分页对象
     */
    @Override
    public PageVO<OperationLogVO> getOperationLogs(OperationLogQuery query) {
        Page<SysOperationLog> page = query.toPageDefaultSortByCreateTime();

        Page<SysOperationLog> operationLogPage = lambdaQuery()
                .like(query.getUsername() != null, SysOperationLog::getUsername, query.getUsername())
                .between(query.getStartTime() != null && query.getEndTime() != null, SysOperationLog::getCreateTime, query.getStartTime(), query.getEndTime())
                .page(page);
        return PageVO.of(operationLogPage, OperationLogVO.class);
    }
}